home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * *
- * MERGEC *
- * This program reads in a Turbo C file and the Assembler *
- * file that tcc produced (with the -S switch) and combines *
- * them into a single file. This function is useful when *
- * trying to debug in Assembler code with a hardware debugger *
- * or if you are just interested in how well Borland *
- * generate Assembler code. *
- * *
- * COMMAND FORMAT: *
- * MERGEC asmsrc csrc mergefile *
- * or *
- * MERGEC filename *
- * and the program will assume the following: *
- * assembler source --> filename.asm *
- * C source ---------> filename.c *
- * "merged source" ---> filename.mer *
- * *
- * *
- * This program was adapted from source by Dan Mick in the *
- * July 1989 issue of "Microsoft Systems Journal." The *
- * original program supported the Microsoft compiler and MASM. *
- * This program only supports Turbo C. *
- * *
- * Send comments or suggestions to: *
- * *
- * Rick Kamp (GENIE: R.KAMP) *
- * (COMPUSERVE: 72311,2346) *
- * *
- * COPYRIGHT (c) Rick Kamp, 1989 *
- * ALL RIGHTS RESERVED *
- * *
- * CHANGE HISTORY: *
- * *
- * Version 1.00 04 Jul 1989 *
- *******************************************************************/
- /* mergec - merge source and assembly files */
-
- #include <stdio.h>
- #include <string.h>
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- FILE *csrc, *asmsrc, *mergefile;
- char buffer[128];
- char rest_of_line[128];
- long sline, line, totslines;
- char filename1[80],filename2[80],filename3[80];
-
- if (argc >4 || argc ==1 || argc==3) {
- printf("usage: mergec asmsrc csrc mergefile\n");
- printf(" or\n");
- printf("usage: mergec filename\n");
- printf(" and the program will assume the following:\n");
- printf(" assembler source --> filename.asm\n");
- printf(" C source ---------> filename.c\n");
- printf(" \"merged source\" ---> filename.mer\n");
- exit(1);
- }
-
- sline = 0;
- if (argc==2) {
- strcpy(filename1, argv[1]);
- strcat(filename1, ".asm\0");
- strcpy(filename2, argv[1]);
- strcat(filename2, ".c\0");
- strcpy(filename3, argv[1]);
- strcat(filename3, ".mer\0");
- }
- else
- {
- strcpy(filename1, argv[1]);
- strcpy(filename2, argv[2]);
- strcpy(filename3, argv[3]);
- }
- if ((asmsrc = fopen(filename1,"r"))==0) {
- printf("Cannot open <%s>\n",filename1);
- exit();
- }
- if ((csrc = fopen(filename2,"r"))== 0) {
- printf("Cannot open <%s>\n",filename2);
- exit();
- }
- if ((mergefile = fopen(filename3,"w"))==0) {
- printf("Cannot open <%s>\n",filename3);
- exit();
- }
-
- setvbuf(csrc,NULL,_IOFBF,8192);
- setvbuf(asmsrc,NULL,_IOFBF,8192);
- setvbuf(mergefile,NULL,_IOFBF,8192);
-
- totslines = 0;
- while (fgets(buffer,128,csrc) != NULL)
- totslines++;
- fseek(csrc,0L,SEEK_SET);
-
- while ((fgets(buffer,128,asmsrc)) !=NULL) {
-
- if (strncmp(buffer,";\t?debug\tL",10) == 0) {
- sscanf(buffer,";\t?debug\tL %ld",&line);
- if (line <= totslines) {
- /* un-comment the following line to set an HP printer to bold text */
- /* You may also set this string to another escape sequence to support *
- * your own printer. */
- /* fprintf(mergefile,"\x1B(s3B"); */
- while (sline < line) {
- fgets(buffer+1,128,csrc);
- fputs(buffer,mergefile);
- ++sline;
- }
- /* un-comment the following line to set an HP printer to normal text */
- /* fprintf(mergefile,"\x1B(s0B\x0D"); */
- }
- }
- else
- if (strncmp(buffer,"\t?debug\tC",9) ==0) {
- continue;
- }
- else
- if (strncmp(buffer,"\t?debug\tS",9) ==0) {
- strcpy(rest_of_line,buffer+10);
- fputs(";*****************************************************************\n"
- ,mergefile);
- fprintf(mergefile,"; source file : %s",rest_of_line);
- fputs(";*****************************************************************\n"
- ,mergefile);
- continue;
- }
- else
- {
- fputs(buffer,mergefile);
- }
- }
- fclose(asmsrc);
- fclose(csrc);
- fclose(mergefile);
- }
-